//
//  CodeShowView.m
//  ZhuiKe55like
//
//  Created by junseek on 15/12/18.
//  Copyright © 2015年 五五来客 李江. All rights reserved.
//

#import "CodeShowView.h"

@interface CodeShowView (){
    NSDictionary *dicCode;
    UIView *view_userContact;
    UIImageView *imageCode;
}


@end
@implementation CodeShowView

-(instancetype)init{
    self=[super init];
    if (self) {
        [self loadDataView];
    }
    return self;
}

-(void)loadDataView{
    self.backgroundColor=RGBACOLOR(0, 0, 0, 0.6);
    self.frame=[UIScreen mainScreen].bounds;
    
    UIControl *closeC=[[UIControl alloc]initWithFrame:self.bounds];
    [closeC addTarget:self action:@selector(closeButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:closeC];
    
    view_userContact=[[UIView alloc]initWithFrame:CGRectMake(20, (kScreenHeight-(kScreenWidth))/2.0, kScreenWidth-40, kScreenWidth)];
    [self addSubview:view_userContact];
    view_userContact.layer.masksToBounds = YES;
    view_userContact.layer.cornerRadius =5;
    view_userContact.layer.borderWidth=1.0;
    view_userContact.layer.borderColor =[[UIColor clearColor] CGColor];
    view_userContact.backgroundColor=[UIColor whiteColor];
    
    imageCode=[RHMethods imageviewWithFrame:CGRectMake(20, 20, W(view_userContact)-40, W(view_userContact)-40) defaultimage:@""];
    [view_userContact addSubview:imageCode];
    
    [view_userContact addSubview:[RHMethods labelWithFrame:CGRectMake(0, YH(imageCode)+10, W(view_userContact), 40) font:fontTxtContent color:rgbpublicColor text:@"扫一扫\n打开页面" textAlignment:NSTextAlignmentCenter]];
    
}

-(void)closeButtonClicked{
    [self hidden];
}

/*
 
 @"content"
 */
- (void)showShareData:(NSDictionary *)dic
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hidden) name:@"push_showLogin" object:nil];
    
    dicCode=dic;
    UIImage *image = [[Utility Share] generatedCode:[dic valueForJSONStrKey:@"content"] withSize:W(imageCode)];
    imageCode.image=image;
    
    // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];
    
    self.hidden = NO;
    self.alpha = 0.0f;
//    view_userContact.frameY=kScreenHeight;
    
    [UIView animateWithDuration:0.3
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         self.alpha = 1.0f;
//                         view_userContact.frameY=kScreenHeight-H(view_userContact);
                         
                     }
                     completion:^(BOOL finished) {
                         
                     }];
    
}

- (void)hidden
{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    //    CGAffineTransform t=CGAffineTransformMakeTranslation(30, -50);
    [UIView animateWithDuration:0.3
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.alpha = 0.0;
//                         view_userContact.frameY=kScreenHeight;
                     }
                     completion:^(BOOL finished) {
                         self.hidden=YES;
                     }];
    
    
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
